Skip to content

Run each copy's patch engine behind a pointer, so the in-process gem tests fit their stack on Windows - #2432

Merged
Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
fix/patch-engine-behind-pointer
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
fix/patch-engine-behind-pointer

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

The problem

The in-process CLI tests run a command on a libtest thread, which has a 2 MiB stack. On main the gem tests of in_process_gem_multi_platform use nearly all of it: on macOS (arm64, debug) remove_base_purl_clears_all_platforms_and_rolls_back needs 1,972 KiB of the 2,048. Windows debug frames are larger. PR runs and push runs have no Windows test job, so only the nightly and a dispatched run show it: main itself overflows there since 0a1709bb2 (STATUS_STACK_OVERFLOW in that test), and so do open PRs built on it.

Where the stack goes: scan -> the nested apply -> apply_gem_package_patch -> apply_package_patch -> the store-copy fan-out -> the engine. Every async fn on that chain awaits apply_package_patch inline, and a debug build keeps room for the awaited future in the caller's poll frame at each call site. The engine's future is the largest of them, so every caller up to the command carried it.

The change

apply_package_patch, rollback_package_patch and rollback_store_copies_holding_patch build the per-copy engine future through a small non-inlined boxed() helper, so their own futures hold a pointer. Two files in core, 36 lines added. No behaviour changes.

Measured

Smallest RUST_MIN_STACK that remove_base_purl_clears_all_platforms_and_rolls_back passes with, macOS arm64 debug:

KiB
main (0a1709bb2) 1,972
this branch 1,500 (fails at 1,450)
this branch merged with main after #2402 1,400 (fails at 1,350)

Windows: the Windows tier, run by dispatch.

Result
main (0a1709bb2) run 46786480812 fails: remove_base_purl_clears_all_platforms_and_rolls_back overflows its stack
this branch (49a28f350) run 46787781256 passes, all 48 jobs

The head adds one commit of doc comments to the tested one.

Since those runs, #2402 landed. It boxes the hand-offs on the CLI side of the same chain, and its Windows tier passed, so main should be back under the limit. This PR takes the engine's future out of every caller's frame, which is the larger share, and the two add up (last row of the table above). The merged tree compiles and lints clean.

Review

/code-review high found nothing blocking and two nits. Done: the helper is a twin of the CLI's ecosystem_dispatch::boxed but for a Send bound, so each doc comment now names the other. Not done: a test that runs the deepest chain on a thread with a stack bounded below 2 MiB, so that a regression fails on every platform and not only in the Windows nightly. A bound that is safe needs measuring on Linux and Windows as well (Linux needs more than macOS for the same test), so it is left for a follow-up; until then the Windows tier is the only detector.

Tests

Run locally on the head commit: cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, cargo check --workspace --all-targets --all-features, the core lib (8,818 passed), and the CLI lib (1,090), apply (207), rollback (142), remove (90), scan (268), get (162), vendor (146) and in_process_gem_multi_platform (9), all passing.

🤖 Generated with Claude Code

The in-process tests run a command on a libtest thread, which has a
2 MiB stack. The deepest chain there is scan -> the nested apply ->
apply_gem_package_patch -> apply_package_patch -> the store-copy fan-out
-> the engine. Every async fn on that chain awaits apply_package_patch
inline, and a debug build keeps room for the awaited future in the
caller's poll frame at each call site. The engine's future is the
largest of them, so every caller up to the command carried it.

apply_package_patch, rollback_package_patch and
rollback_store_copies_holding_patch now build the per-copy engine
future through a non-inlined boxed(), so their own futures hold a
pointer. No behaviour changes.

On macOS (arm64, debug) the smallest stack that
remove_base_purl_clears_all_platforms_and_rolls_back of
in_process_gem_multi_platform passes with goes from 1972 KiB to
1500 KiB. On Windows that test overflowed the stack on a branch that
adds nothing to the chain beyond current main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Core's boxed (for the patch engines) and the CLI's (for its command
frames) are the same helper but for a Send bound. Each doc comment now
names the other, so a change to one is made to both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 02:05
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Mechanical future boxing for stack size with documented parity to an existing CLI pattern; patch semantics unchanged per PR and tests.

Overview
Stack-only fix for debug builds where deep async chains (apply / rollback store-copy fan-out) inlined large poll frames and overflowed libtest’s 2 MiB stack on Windows gem tests.

Introduces a non-inlined patch::apply::boxed helper (with Send) that builds each per-copy patch/rollback future on the stack and returns a Pin<Box<dyn Future>>, so callers only retain a pointer. apply_package_patch, rollback_package_patch, and rollback_store_copies_holding_patch route their per-copy engines through this helper instead of awaiting those futures inline.

The CLI’s existing ecosystem_dispatch::boxed gets matching doc comments that point at the core twin (no Send there). No intended runtime behavior change—only poll-frame / stack footprint.

Reviewed by Cursor Bugbot for commit 4124614. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. The in-process gem tests nearly fill a test thread's 2 MiB stack, and on Windows debug they overflow it (STATUS_STACK_OVERFLOW in remove_base_purl_clears_all_platforms_and_rolls_back). This PR boxes each store copy's patch-engine future behind a non-inlined boxed() helper in apply_package_patch, rollback_package_patch and rollback_store_copies_holding_patch. Every caller up the chain then holds a pointer instead of the engine's large future. Behaviour does not change.

Risk: low. It adds one heap allocation per patched copy and keeps the same Send bound. Each engine call is awaited exactly as before.

Look here

Verified

  • Read the whole diff: 3 files, +45/−4, with no unrelated edits.
  • Merged with current main locally (it already has Fix agent apply patching gem homes Bundler never loads (#2313) #2402's CLI-side boxing). The merge has no conflict, and in_process_gem_multi_platform passes on it: 9 of 9 pass (Linux, debug).
  • No open review threads. CHANGELOG.md is untouched.
  • ci-ok and clippy are green on the head.
  • The Windows proof is in the description: the dispatched run on the tested commit passed, and main overflowed.

Changes I made. None.

Open questions. None. The follow-up in the body (a test on a thread with a bounded stack, so a regression fails on every platform) is not needed for this PR.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed the full diff at 4124614: the three engine calls are boxed at the same await points with the same arguments and Send bound, so behaviour is unchanged apart from one allocation per copy. No defects found.

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 3946d4d Dec 2, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/patch-engine-behind-pointer branch December 2, 2026 04:30
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
Resolve the conflict with main's file-mode support (#2433) and its boxed
engine futures (#2432):
- keep one `boxed` helper, main's (both sides added the same function);
- thread main's new `mode` argument of `stage_write` through this branch's
  shared `stage`; the optional RECORD write passes `None`, so it clears no
  permission bits;
- compute the sidecar fixup files once, before the RECORD plan, as this
  branch does, reading main's `(file, AppliedVia)` entries of `written`;
- give this branch's tests the new `mode` field and argument.

Assisted-by: Claude Code:claude-opus-5-5
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Dec 2, 2026
…s-dir' into fix/vex-pnpm-store-windows

The base branch took in main, which holds #2430 (the rule this branch
extends) and the two fixes for the stack that the in-process gem tests
overflow on Windows (#2402, #2432). Without them the Windows test shard
fails on a test this branch does not touch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants